package com.sqz.controller;

import com.sqz.pojo.RightsEntity;
import com.sqz.pojo.RolesEntity;
import com.sqz.pojo.ext.RoleRightExt;
import com.sqz.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    //    @RequestMapping("/list")
//    public String list(ModelMap model) {
//
//        List<RoleRightExt> roleList = roleService.roleList();
//        model.addAttribute("roleList", roleList);
//        return "role/role_list";
//    }
    @RequestMapping("/list")
    @ResponseBody
    public List<RoleRightExt> list(ModelMap model) {

        List<RoleRightExt> roleList = roleService.roleList();
        model.addAttribute("roleList", roleList);
        return roleList;
    }

    @RequestMapping("/addView")
    public String addView(ModelMap model) {

        List<RightsEntity> allRights = roleService.allRights();
        model.addAttribute("allRights", allRights);
        return "role/role_add";
    }

    @RequestMapping("addRole")
    public String addRole(String roleName, String rights) {

        String s = roleName;
        String list = rights;
        roleService.addRole(roleName, rights);

        return "redirect:addView";
    }


}
